package com.byzk.p2p.admin.system.controller;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.byzk.p2p.admin.base.controller.BaseController;
import com.byzk.p2p.admin.base.util.DateUtils;
import com.byzk.p2p.admin.base.util.ExcelUtil;
import com.byzk.p2p.admin.base.util.PageInfo;
import com.byzk.p2p.admin.borrow.dao.BorrowDao;
import com.byzk.p2p.admin.borrow.dao.TenderDao;
import com.byzk.p2p.admin.borrow.service.BorrowService;
import com.byzk.p2p.admin.borrow.service.TenderService;
import com.byzk.p2p.admin.borrow.vo.BorrowRepayExportVo;
import com.byzk.p2p.admin.borrow.vo.BorrowTempVo;
import com.byzk.p2p.admin.borrow.vo.BorrowVo;
import com.byzk.p2p.admin.borrow.vo.ChangeAwaitVo;
import com.byzk.p2p.admin.borrow.vo.UserTenderExportVo;
import com.byzk.p2p.admin.borrow.vo.UserTenderVo;
import com.byzk.p2p.admin.log.dao.ThirdMsgRecordDao;
import com.byzk.p2p.admin.log.dto.ThirdMsgRecord;
import com.byzk.p2p.admin.money.dao.RechargeDao;
import com.byzk.p2p.admin.money.dao.WithdrawDao;
import com.byzk.p2p.admin.money.service.BorrowPaymentService;
import com.byzk.p2p.admin.money.service.FundRecordService;
import com.byzk.p2p.admin.money.util.BaofuUtil;
import com.byzk.p2p.admin.money.util.FundRecordType;
import com.byzk.p2p.admin.money.util.RechargeStatus;
import com.byzk.p2p.admin.money.util.WithdrawStatus;
import com.byzk.p2p.admin.money.vo.BorrowPaymentVo;
import com.byzk.p2p.admin.money.vo.FundRecordUserExportVo;
import com.byzk.p2p.admin.money.vo.FundRecordUserVo;
import com.byzk.p2p.admin.money.vo.RechargeRecordVo;
import com.byzk.p2p.admin.money.vo.WithdrawRecordVo;
import com.byzk.p2p.admin.system.service.GoodBuyService;
import com.byzk.p2p.admin.system.vo.GoodBuyExportVo;
import com.byzk.p2p.admin.system.vo.GoodBuyVo;
import com.byzk.p2p.admin.user.dao.UserAccountDao;
import com.byzk.p2p.admin.user.dto.UserAccount;
import com.byzk.p2p.admin.user.service.UserAccountService;
import com.byzk.p2p.admin.user.vo.UserAccountVo;

import java.text.DecimalFormat;
@Controller
@RequestMapping("/admin/export")
@Scope("prototype")
public class ExportController extends BaseController {

	@Autowired
	private FundRecordService fundRecordService;
	@Autowired
	private TenderService tenderService;
	@Autowired
	private BorrowService borrowService;
	@Autowired
	private BorrowPaymentService borrowPaymentService;
	@Autowired
	private GoodBuyService goodBuyService;
	@Autowired
	private ThirdMsgRecordDao thirdMsgRecordDao;
	@Autowired
	private WithdrawDao withdrawDao;
	@Autowired
	private RechargeDao rechargeDao;
	@Autowired
	private BorrowDao  borrowDao;
	@Autowired
	private UserAccountDao userAccountDao;
	@Autowired
	private TenderDao tenderDao;
	@Autowired
	private UserAccountDao accountDao;
	  
	/**
	 * 导出用户资金流水信息
	 * @param exportVo 导出对象
	 * @param ids 勾选id
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="/fund",method=RequestMethod.POST)
	public void exportFundRecord(@ModelAttribute FundRecordUserExportVo exportVo,
								 @RequestParam("ids") List<String> ids) throws Exception {
		exportVo.setIds(CollectionUtils.isNotEmpty(ids)?ids:null);
		if (StringUtils.isNotBlank(exportVo.getCreateTime())) {
			exportVo.setCreateTimeBegin(DateUtils.getRealDate(DateUtils.convert(exportVo.getCreateTime().split("~")[0], DateUtils.YEAR_MOUTH_DAY_FORMAT)));
			exportVo.setCreateTimeEnd(DateUtils.getFullDate(DateUtils.convert(exportVo.getCreateTime().split("~")[1], DateUtils.YEAR_MOUTH_DAY_FORMAT)));
		}
		List<FundRecordUserVo> fundRecordUserVos=fundRecordService.exportList(exportVo);
		for (FundRecordUserVo temp : fundRecordUserVos) {
			if(FundRecordType.Type.RECHARGE.index == temp.getType().intValue()){
				temp.setFundType(String.valueOf(FundRecordType.Type.RECHARGE.name));
			}else if(FundRecordType.Type.WITHDRAW.index == temp.getType().intValue()){
				temp.setFundType(FundRecordType.Type.WITHDRAW.name);
			}else if(FundRecordType.Type.TENDER.index == temp.getType().intValue()){
				temp.setFundType(FundRecordType.Type.TENDER.name);
			}else if(FundRecordType.Type.REPAY.index == temp.getType().intValue()){
				temp.setFundType(FundRecordType.Type.REPAY.name);
			}else if(FundRecordType.Type.BUY.index == temp.getType().intValue()){
				temp.setFundType(FundRecordType.Type.BUY.name);
			}else if(FundRecordType.Type.CHANGE.index == temp.getType().intValue()){
				temp.setFundType(FundRecordType.Type.CHANGE.name);
			}else if(FundRecordType.Type.UNFREEZEN.index == temp.getType().intValue()){
				temp.setFundType(FundRecordType.Type.UNFREEZEN.name);
			}else if(FundRecordType.Type.FREEZEN.index == temp.getType().intValue()){
				temp.setFundType(FundRecordType.Type.FREEZEN.name);
			}else if(FundRecordType.Type.GET.index == temp.getType().intValue()){
				temp.setFundType(FundRecordType.Type.GET.name);
			}else if(FundRecordType.Type.REGISTER.index == temp.getType().intValue()){
				temp.setFundType(FundRecordType.Type.REGISTER.name);
			}else if(FundRecordType.Type.INVITE.index == temp.getType().intValue()){
				temp.setFundType(FundRecordType.Type.INVITE.name);
			}else if(FundRecordType.Type.FEE.index == temp.getType().intValue()){
				temp.setFundType(FundRecordType.Type.FEE.name);
			}else if(FundRecordType.Type.TENDER_FREEZEN.index == temp.getType().intValue()){
				temp.setFundType(FundRecordType.Type.TENDER_FREEZEN.name);
			}else if(FundRecordType.Type.TENDER_SUCCESS.index == temp.getType().intValue()){
				temp.setFundType(FundRecordType.Type.TENDER_SUCCESS.name);
			}
		}
		FundRecordUserVo vo = new FundRecordUserVo();
		ExcelUtil<FundRecordUserVo> excel = new ExcelUtil<FundRecordUserVo>();
		export(excel.exportExcel(vo ,fundRecordUserVos));
	}
	
	/**
	 * 导出提现信息
	 * @param exportVo 导出对象 
	 * @param ids 勾选id
	 * @param status 提现状态
	 * @throws Exception
	 */
	@RequestMapping(value = "/withdraw", method = RequestMethod.POST)
	public void exportWithdrawRecord(@ModelAttribute WithdrawRecordVo exportVo, @RequestParam("ids") List<String> ids,
			@RequestParam(value = "createTimeBegin", required = false) String createTimeBegin,
			@RequestParam(value = "createTimeEnd", required = false) String createTimeEnd,
			@RequestParam(value = "status") String status) throws Exception {
		exportVo.setStatus(status);
		if (StringUtils.isNotBlank(exportVo.getMatch())) {
			if ("GT".equals(exportVo.getMatch())) {
				exportVo.setMatchGT(exportVo.getMatch());
			} else if ("LT".equals(exportVo.getMatch())) {
				exportVo.setMatchLT(exportVo.getMatch());
			} else if ("GE".equals(exportVo.getMatch())) {
				exportVo.setMatchGE(exportVo.getMatch());
			} else if ("LE".equals(exportVo.getMatch())) {
				exportVo.setMatchLE(exportVo.getMatch());
			} else if ("NE".equals(exportVo.getMatch())) {
				exportVo.setMatchNE(exportVo.getMatch());
			} else if ("EQ".equals(exportVo.getMatch())) {
				exportVo.setMatchEQ(exportVo.getMatch());
			}
		}
		if (StringUtils.isBlank(exportVo.getUsername())) {
			exportVo.setUsername(null);
		}
		if (StringUtils.isBlank(exportVo.getIsOffLine())) {
			exportVo.setIsOffLine(null);
		}
		if (StringUtils.isBlank(exportVo.getStatus())) {
			exportVo.setStatus(null);
		}
		if (StringUtils.isNotBlank(exportVo.getStatus().split(",")[0])) {
			exportVo.setStatus(exportVo.getStatus().split(",")[0]);
		}
		if (StringUtils.isNotBlank(createTimeBegin)) {
			exportVo.setPublishTimeStart(DateUtils.getRealDate(DateUtils.convert(createTimeBegin, DateUtils.YEAR_MOUTH_DAY_FORMAT)));
		}
		if (StringUtils.isNotBlank(createTimeEnd)) {
			exportVo.setPublishTimeEnd(DateUtils.getFullDate(DateUtils.convert(createTimeEnd, DateUtils.YEAR_MOUTH_DAY_FORMAT)));
		}
		Integer count = withdrawDao.countByStatus(exportVo);
		exportVo.setLimit(count);
		List<WithdrawRecordVo> withdrawList = withdrawDao.listByStatus(exportVo);
		for (WithdrawRecordVo temp : withdrawList) {
			if (WithdrawStatus.APPLY.equals(temp.getStatus())) {
				temp.setStatus("待审核");
			} else if (WithdrawStatus.APPLY_FAILURE.equals(temp.getStatus())) {
				temp.setStatus("审核失败");
			} else if (WithdrawStatus.FAILURE.equals(temp.getStatus())) {
				temp.setStatus("转账失败");
			} else if (WithdrawStatus.SUCCESS.equals(temp.getStatus())) {
				temp.setStatus("转账成功");
			} else if (WithdrawStatus.TRANSFER.equals(temp.getStatus())) {
				temp.setStatus("转账中");
			}
			temp.setBankCode(BaofuUtil.bankMap.get(temp.getBankCode()));
		}
		ExcelUtil<WithdrawRecordVo> excel = new ExcelUtil<WithdrawRecordVo>();
		WithdrawRecordVo vo = new WithdrawRecordVo();
		export(excel.exportExcel(vo, withdrawList));
	}
	
	/**
	 * 导出充值信息
	 * @param exportVo 导出对象
	 * @param ids 勾选id
	 * @param status 充值状态
	 * @throws Exception
	 */
	@RequestMapping(value="/recharge",method=RequestMethod.POST)
	public void exportRechargeRecord(@ModelAttribute(value = "exportVo") RechargeRecordVo exportVo,
			@RequestParam(value = "createTimeBegin", required = false) String createTimeBegin,
			@RequestParam(value = "createTimeEnd", required = false) String createTimeEnd,
			 @RequestParam(value="isOffLine",required=false)String isOffLine,
			@RequestParam(value = "ids") List<String> ids, @RequestParam(value = "status") String status)
					throws Exception {
		exportVo.setStatus(status);
		if (StringUtils.isNotBlank(exportVo.getMatch())) {
			if ("GT".equals(exportVo.getMatch())) {
				exportVo.setMatchGT(exportVo.getMatch());
			} else if ("LT".equals(exportVo.getMatch())) {
				exportVo.setMatchLT(exportVo.getMatch());
			} else if ("GE".equals(exportVo.getMatch())) {
				exportVo.setMatchGE(exportVo.getMatch());
			} else if ("LE".equals(exportVo.getMatch())) {
				exportVo.setMatchLE(exportVo.getMatch());
			} else if ("NE".equals(exportVo.getMatch())) {
				exportVo.setMatchNE(exportVo.getMatch());
			} else if ("EQ".equals(exportVo.getMatch())) {
				exportVo.setMatchEQ(exportVo.getMatch());
			}
		}
		// List<RechargeRecordVo>
		// rechargeList=rechargeService.exportList(exportVo);
		if (StringUtils.isBlank(exportVo.getUsername())) {
			exportVo.setUsername(null);
		}
		if (StringUtils.isBlank(exportVo.getIsOffLine())) {
			exportVo.setIsOffLine(null);
		}
		if (StringUtils.isBlank(exportVo.getStatus())) {
			exportVo.setStatus(null);
		}
		if (StringUtils.isNotBlank(exportVo.getStatus().split(",")[0])) {
			exportVo.setStatus(exportVo.getStatus().split(",")[0]);
		}
		if (StringUtils.isNotBlank(createTimeBegin)) {
			exportVo.setPublishTimeStart(DateUtils.getRealDate(DateUtils.convert(createTimeBegin, DateUtils.YEAR_MOUTH_DAY_FORMAT)));
		}
		if (StringUtils.isNotBlank(createTimeEnd)) {
			exportVo.setPublishTimeEnd(DateUtils.getFullDate(DateUtils.convert(createTimeEnd, DateUtils.YEAR_MOUTH_DAY_FORMAT)));
		}
		Integer count = rechargeDao.countByMethod(exportVo);
		exportVo.setStart(0);
		exportVo.setLimit(count);
		List<RechargeRecordVo> rechargeList = rechargeDao.listByMethod(exportVo);
		for (RechargeRecordVo temp : rechargeList) {
			if (RechargeStatus.WAITING.equals(temp.getStatus())) {
				temp.setStatus("等待支付");
			} else if (RechargeStatus.EXPIRED.equals(temp.getStatus())) {
				temp.setStatus("支付取消");
			} else if (WithdrawStatus.SUCCESS.equals(temp.getStatus())) {
				temp.setStatus("支付成功");
			} else if (WithdrawStatus.FAILURE.equals(temp.getStatus())) {
				temp.setStatus("支付失败");
			}
		}
		ExcelUtil<RechargeRecordVo> excel = new ExcelUtil<RechargeRecordVo>();
		RechargeRecordVo vo = new RechargeRecordVo();
		export(excel.exportExcel(vo, rechargeList));
	}

	/**
	 * 导出投资记录
	 * @param exportVo 导出对象
	 * @param ids 勾选id
	 * @throws Exception
	 */
	@RequestMapping(value="/tender",method=RequestMethod.POST)
	public void exportTenderRecord(@ModelAttribute(value="exportVo") UserTenderExportVo exportVo,
									@RequestParam(value="ids") List<String> ids) throws Exception{
		exportVo.setIds(CollectionUtils.isNotEmpty(ids)?ids:null);
		if (StringUtils.isNotBlank(exportVo.getTenderTime())) {
			exportVo.setCreateTimeBegin(DateUtils.getRealDate(DateUtils.convert(exportVo.getTenderTime().split("~")[0], DateUtils.YEAR_MOUTH_DAY_FORMAT)));
			exportVo.setCreateTimeEnd(DateUtils.getFullDate(DateUtils.convert(exportVo.getTenderTime().split("~")[1], DateUtils.YEAR_MOUTH_DAY_FORMAT)));
		}
		List<UserTenderVo> userTenderList = tenderService.exportList(exportVo);
		for (UserTenderVo temp : userTenderList) {
			if("Y".equals(temp.getIsAuto())){
				temp.setIsAuto("自动");
			}else if("N".equals(temp.getIsAuto())){
				temp.setIsAuto("手动");
			}
	        if("MONTH".equals(temp.getDateUtil())){
				temp.setDateUtil(temp.getDeadline()+"个月");
			}else if("DAY".equals(temp.getDateUtil())){
				temp.setDateUtil(temp.getDeadline()+"天");
			}else if("YEAR".equals(temp.getDateUtil())){
				temp.setDateUtil(temp.getDeadline()+"年");
			}
	        if (temp.getRewardPercent() == null) {
				temp.setRewardPercent(0.00);
			}
		}
		ExcelUtil<UserTenderVo> excel = new ExcelUtil<UserTenderVo>();
		UserTenderVo vo = new UserTenderVo();
		export(excel.exportExcel(vo ,userTenderList));
	}
	
	/**
	 * 导出借款标还款情况
	 * @param exportVo 导出对象
	 * @param ids 勾选id
	 * @throws Exception
	 */
	@RequestMapping(value="/borrow/repay",method=RequestMethod.POST)
	public void exportBorrowRepay(@ModelAttribute(value="exportVo") BorrowRepayExportVo exportVo,
									@RequestParam(value="ids") List<String> ids) throws Exception{
		exportVo.setIds(CollectionUtils.isNotEmpty(ids)?ids:null);
		if (StringUtils.isNotBlank(exportVo.getExpectPaymentDate())) {
			exportVo.setExpectPaymentDateBegin(DateUtils.getRealDate(DateUtils.convert(exportVo.getExpectPaymentDate().split("~")[0], DateUtils.YEAR_MOUTH_DAY_FORMAT)));
			exportVo.setExpectPaymentDateEnd(DateUtils.getFullDate(DateUtils.convert(exportVo.getExpectPaymentDate().split("~")[1], DateUtils.YEAR_MOUTH_DAY_FORMAT)));
		}
		if (StringUtils.isNotBlank(exportVo.getActualPaymentDate())) {
			exportVo.setActualPaymentDateBegin(DateUtils.getRealDate(DateUtils.convert(exportVo.getActualPaymentDate().split("~")[0], DateUtils.YEAR_MOUTH_DAY_FORMAT)));
			exportVo.setActualPaymentDateEnd(DateUtils.getFullDate(DateUtils.convert(exportVo.getActualPaymentDate().split("~")[1], DateUtils.YEAR_MOUTH_DAY_FORMAT)));
		}
		List<BorrowTempVo> borrowRepayList = borrowService.exportList(exportVo);
		ExcelUtil<BorrowTempVo> excel = new ExcelUtil<BorrowTempVo>();
		BorrowTempVo vo = new BorrowTempVo();
		export(excel.exportExcel(vo ,borrowRepayList));
	}
	
	
	/**
	 * 导出借款标还款明细情况
	 * @param exportVo 导出对象
	 * @param ids 勾选id
	 * @throws Exception
	 */
	@RequestMapping(value="/borrow/repay/detail",method=RequestMethod.POST)
	public void exportBorrowRepayDetail(@ModelAttribute(value="exportVo") BorrowRepayExportVo exportVo,
									@RequestParam(value="ids") List<String> ids) throws Exception{
		exportVo.setIds(CollectionUtils.isNotEmpty(ids)?ids:null);
		if (StringUtils.isNotBlank(exportVo.getExpectPaymentDate())) {
			exportVo.setExpectPaymentDateBegin(DateUtils.getRealDate(DateUtils.convert(exportVo.getExpectPaymentDate().split("~")[0], DateUtils.YEAR_MOUTH_DAY_FORMAT)));
			exportVo.setExpectPaymentDateEnd(DateUtils.getFullDate(DateUtils.convert(exportVo.getExpectPaymentDate().split("~")[1], DateUtils.YEAR_MOUTH_DAY_FORMAT)));
		}
		if (StringUtils.isNotBlank(exportVo.getActualPaymentDate())) {
			exportVo.setActualPaymentDateBegin(DateUtils.getRealDate(DateUtils.convert(exportVo.getActualPaymentDate().split("~")[0], DateUtils.YEAR_MOUTH_DAY_FORMAT)));
			exportVo.setActualPaymentDateEnd(DateUtils.getFullDate(DateUtils.convert(exportVo.getActualPaymentDate().split("~")[1], DateUtils.YEAR_MOUTH_DAY_FORMAT)));
		}
		List<BorrowPaymentVo> borrowUnRepayList = borrowPaymentService.exportList(exportVo);
		ExcelUtil<BorrowPaymentVo> excel = new ExcelUtil<BorrowPaymentVo>();
		BorrowPaymentVo vo = new BorrowPaymentVo();
		export(excel.exportExcel(vo ,borrowUnRepayList));
	}
	/**
	 * 
	 * @param exportVo
	 * @param ids
	 * @throws Exception
	 */
	@RequestMapping(value="/goodBuy",method=RequestMethod.POST)
	public void exportGoodBuy(@ModelAttribute(value="exportVo") GoodBuyExportVo exportVo,
									@RequestParam(value="ids") List<String> ids) throws Exception{
		exportVo.setIds(CollectionUtils.isNotEmpty(ids)?ids:null);
		List<GoodBuyVo> goodBuyList = goodBuyService.exportList(exportVo);
		ExcelUtil<GoodBuyVo> excel = new ExcelUtil<GoodBuyVo>();
		GoodBuyVo vo = new GoodBuyVo();
		export(excel.exportExcel(vo ,goodBuyList));
	}
	
	
	/**
	 * 
	* <p>Description:导出三方消息推送 </p>
	* <p>Company:xbd </p>
	* @author:lilei
	* @date:2016年10月21日下午3:40:38
	 */
	@RequestMapping(value = "/thirdMsg", method = RequestMethod.POST)
	public void exportThirdMsg(@ModelAttribute(value = "exportVo") ThirdMsgRecord exportVo,
			@RequestParam(value = "sendTimeFrom", required = false) String sendTimeFrom,
			@RequestParam(value = "sendTimeTo", required = false) String sendTimeTo,
			@RequestParam(value = "ids") List<String> ids) throws Exception {

		exportVo.setIds(CollectionUtils.isNotEmpty(ids) ? ids : null);
		Map<String, Object> queryMap = new HashMap<String, Object>();
		if (StringUtils.isNotBlank(exportVo.getPhone())) {
			queryMap.put("phone", exportVo.getPhone());
		}
		if (StringUtils.isNotBlank((exportVo.getType().split(","))[0]) && !"-1".equals((exportVo.getType().split(","))[0])) {
			queryMap.put("type", (exportVo.getType().split(","))[0]);
		}
		if (StringUtils.isNotBlank(sendTimeTo)) {
			queryMap.put("sendTimeTo", sendTimeTo);
		}
		if (StringUtils.isNotBlank(sendTimeFrom)) {
			queryMap.put("sendTimeFrom", sendTimeFrom);
		}
		List<ThirdMsgRecord> msgInfoList = new ArrayList<ThirdMsgRecord>();
		List<ThirdMsgRecord> msgList = thirdMsgRecordDao.recordListByTerm(queryMap);
		for (ThirdMsgRecord list : msgList) {
			if (StringUtils.isNotBlank(list.getType()) && list.getType().equals("0")) {
				list.setType("充值");
			} else if (StringUtils.isNotBlank(list.getType()) && list.getType().equals("1")) {
				list.setType("提现");
			} else if (StringUtils.isNotBlank(list.getType()) && list.getType().equals("22")) {
				list.setType("其他");
			}else if (StringUtils.isNotBlank(list.getType()) && list.getType().equals("-1")) {
				list.setType(null);
			}else {
				continue;
			}
			msgInfoList.add(list);
		}
		ExcelUtil<ThirdMsgRecord> excel = new ExcelUtil<ThirdMsgRecord>();
		ThirdMsgRecord vo = new ThirdMsgRecord();
		export(excel.exportExcel(vo, msgInfoList));
	}
	
	
	
	
	
	/**
	 * 
	* <p>Description: 借款标导出功能</p>
	* <p>Company:xbd </p>
	* @author:lilei
	* @date:2016年11月29日上午9:13:28
	 */
	@RequestMapping("/borrow/list")
	public void listBorrow(@ModelAttribute(value = "exportVo") BorrowVo exportVo,
			@RequestParam(value = "status", required = false) String status,
			@RequestParam(value = "createTimeBegin", required = false) String createTimeBegin,
			@RequestParam(value = "createTimeEnd", required = false) String createTimeEnd,
			@RequestParam(value = "borrow_title", required = false) String borrow_title) throws Exception {
		BorrowVo borrowVo = new BorrowVo();
		if (StringUtils.isNotBlank(status)) {
			borrowVo.setStatus(status);
		}
		if (StringUtils.isNotBlank(createTimeBegin)) {
			borrowVo.setCreateTimeBegin(
					DateUtils.getRealDate(DateUtils.convert(createTimeBegin, DateUtils.YEAR_MOUTH_DAY_FORMAT)));
		}
		if (StringUtils.isNotBlank(createTimeEnd)) {
			borrowVo.setCreateTimeEnd(
					DateUtils.getFullDate(DateUtils.convert(createTimeEnd, DateUtils.YEAR_MOUTH_DAY_FORMAT)));
		}
		if (StringUtils.isNotBlank(borrow_title)) {
			borrow_title = java.net.URLDecoder.decode(borrow_title, "UTF-8");
			borrowVo.setTitle(borrow_title);
		}
		int index = 1;
		int count = borrowDao.countBorrowAll(borrowVo);
		borrowVo.setLimit(count);
		List<BorrowVo> borrowList2 = new ArrayList<BorrowVo>();
		List<BorrowVo> borrowList = borrowDao.listBorrow(borrowVo);

		if (borrowList != null && borrowList.size() > 0) {

			for (BorrowVo borrow : borrowList) {

				borrow.setIndex(index);
				// 借款标状态
				if ("borrow".equals(borrow.getStatus())) {
					borrow.setStatus("投资中");
				} else if ("check".equals(borrow.getStatus())) {
					borrow.setStatus("复审中");
				} else if ("expire".equals(borrow.getStatus())) {
					borrow.setStatus("已过期/流标");
				} else if ("pay".equals(borrow.getStatus())) {
					borrow.setStatus("还款中");
				} else if ("complete".equals(borrow.getStatus())) {
					borrow.setStatus("已还完");
				} else if ("preview".equals(borrow.getStatus())) {
					borrow.setStatus("预约中");
				} else {
					borrow.setStatus("其他");
				}
				// 还款类型
				if (1 == borrow.getPaymentMode()) {
					borrow.setPaymentModeName("一次性还款");
				} else if (2 == borrow.getPaymentMode()) {
					borrow.setPaymentModeName("等额本息");
				} else if (3 == borrow.getPaymentMode()) {
					borrow.setPaymentModeName("按月付息到期还本");
				} else {
					borrow.setPaymentModeName("其他");
				}
				// 借款期数
				if ("DAY".equals(borrow.getDateUtil())) {
					borrow.setFullDeadLine(borrow.getDeadline() + "天");
				} else if ("MONTH".equals(borrow.getDateUtil())) {
					borrow.setFullDeadLine(borrow.getDeadline() + "月");
				} else {
					borrow.setFullDeadLine(borrow.getDeadline() + "");
				}
				// 年化率
				if (borrow.getRewardPercent() != null) {
					borrow.setFullPercent(
							(new DecimalFormat("#.00").format(borrow.getRewardPercent() + borrow.getPercent())) + "%");
				} else {
					borrow.setFullPercent(borrow.getPercent() + "%");
				}

				if (3 == borrow.getProductId()) {
					borrow.setProductName("车贷E通");
				} else if (4 == borrow.getProductId()) {
					borrow.setProductName("车商贷");
				} else if (5 == borrow.getProductId()) {
					borrow.setProductName("房E贷");
				} else if (6 == borrow.getProductId()) {
					borrow.setProductName("商易贷");
				} else if (7 == borrow.getProductId()) {
					borrow.setProductName("抵押贷");
				} else if (8 == borrow.getProductId()) {
					borrow.setProductName("担保标");
				} else if (9 == borrow.getProductId()) {
					borrow.setProductName("测试标");
				} else if (10 == borrow.getProductId()) {
					borrow.setProductName("项目贷");
				} else {
					borrow.setProductName("");
				}
				borrowList2.add(borrow);
				index++;
			}
		}
		ExcelUtil<BorrowVo> excel = new ExcelUtil<BorrowVo>();
		BorrowVo vo = new BorrowVo();
		export(excel.exportExcel(vo, borrowList2));
	}
	
	
	/**
	 * 
	* <p>Description:用户账户导出功能</p>
	* <p>Company:xbd </p>
	* @author:lilei
	* @date:2016年12月22日下午3:22:23
	 */
	@RequestMapping(value="/userAccount")
	public void listUserAccount(Model model,
			@RequestParam(value = "index", required = false, defaultValue = "1") int index,
			@RequestParam(value = "username", required = false) String username,
			@RequestParam(value = "match", required = false) String match,
			@RequestParam(value = "amount", required = false) Double amount) throws Exception {
		UserAccountVo userAccountVo = new UserAccountVo();
		if (StringUtils.isNotBlank(username)) {
			username = java.net.URLDecoder.decode(username, "UTF-8");
			userAccountVo.setMatchUser(username);
			model.addAttribute("username", username);
		}
		if (StringUtils.isNotBlank(match)) {
			// EQ("="), GT(">"), LT("<"), GE(">="), LE("<="), NE("<>");
			if (match.equals("EQ")) {
				userAccountVo.setMatchEQ(match);
			} else if (match.equals("GT")) {
				userAccountVo.setMatchGT(match);
			} else if (match.equals("LT")) {
				userAccountVo.setMatchLT(match);
			} else if (match.equals("GE")) {
				userAccountVo.setMatchGE(match);
			} else if (match.equals("LE")) {
				userAccountVo.setMatchLE(match);
			} else if (match.equals("NE")) {
				userAccountVo.setMatchNE(match);
			}
			model.addAttribute("match", match);
		}
		if (amount != null) {
			userAccountVo.setTotalAmount(amount);
			model.addAttribute("amount", amount);
		}
		int count=userAccountDao.count(userAccountVo);
		userAccountVo.setIndex(index);
		userAccountVo.setLimit(count);
		List<UserAccountVo> list= new ArrayList<UserAccountVo>();
		List<UserAccountVo> voList=userAccountDao.list(userAccountVo);
		for (UserAccountVo vo : voList) {
			vo.setIndex(index);
			Integer userId=vo.getUserId();
			ChangeAwaitVo await=tenderDao.sumChangeAwait(userId,null);
			//待收总额
			UserAccount account=accountDao.getByUserId(userId);
			vo.setAwait(tenderDao.sumAwaitTotal(userId)+await.getPaymentTotal()+account.getAwait());
			list.add(vo);
			index++;
		}
		ExcelUtil<UserAccountVo> excel = new ExcelUtil<UserAccountVo>();
		UserAccountVo vo = new UserAccountVo();
		export(excel.exportExcel(vo, list)); 
	}
}
